25#include "config/aom_config.h"
32#include "aom/aom_integer.h"
34#include "aom_dsp/bitwriter_buffer.h"
35#include "aom_ports/aom_timer.h"
36#include "av1/ratectrl_rtc.h"
37#include "common/args.h"
38#include "common/tools_common.h"
39#include "common/video_writer.h"
40#include "examples/encoder_util.h"
41#include "examples/multilayer_metadata.h"
43#define OPTION_BUFFER_SIZE 1024
44#define MAX_NUM_SPATIAL_LAYERS 4
49 const char *output_filename;
50 char options[OPTION_BUFFER_SIZE];
51 struct AvxInputContext input_ctx[MAX_NUM_SPATIAL_LAYERS];
60 bool scale_factors_explicitly_set;
61 const char *multilayer_metadata_file;
72enum { kSkip = 0, kDeltaQ = 1, kDeltaLF = 2, kReference = 3 };
74static const arg_def_t outputfile =
75 ARG_DEF(
"o",
"output", 1,
"Output filename");
76static const arg_def_t frames_arg =
77 ARG_DEF(
"f",
"frames", 1,
"Number of frames to encode");
78static const arg_def_t threads_arg =
79 ARG_DEF(
"th",
"threads", 1,
"Number of threads to use");
80static const arg_def_t width_arg = ARG_DEF(
"w",
"width", 1,
"Source width");
81static const arg_def_t height_arg = ARG_DEF(
"h",
"height", 1,
"Source height");
82static const arg_def_t timebase_arg =
83 ARG_DEF(
"t",
"timebase", 1,
"Timebase (num/den)");
84static const arg_def_t bitrate_arg = ARG_DEF(
85 "b",
"target-bitrate", 1,
"Encoding bitrate, in kilobits per second");
86static const arg_def_t spatial_layers_arg =
87 ARG_DEF(
"sl",
"spatial-layers", 1,
"Number of spatial SVC layers");
88static const arg_def_t temporal_layers_arg =
89 ARG_DEF(
"tl",
"temporal-layers", 1,
"Number of temporal SVC layers");
90static const arg_def_t layering_mode_arg =
91 ARG_DEF(
"lm",
"layering-mode", 1,
"Temporal layering scheme.");
92static const arg_def_t kf_dist_arg =
93 ARG_DEF(
"k",
"kf-dist", 1,
"Number of frames between keyframes");
94static const arg_def_t scale_factors_arg =
95 ARG_DEF(
"r",
"scale-factors", 1,
"Scale factors (lowest to highest layer)");
96static const arg_def_t min_q_arg =
97 ARG_DEF(NULL,
"min-q", 1,
"Minimum quantizer");
98static const arg_def_t max_q_arg =
99 ARG_DEF(NULL,
"max-q", 1,
"Maximum quantizer");
100static const arg_def_t speed_arg =
101 ARG_DEF(
"sp",
"speed", 1,
"Speed configuration");
102static const arg_def_t aqmode_arg =
103 ARG_DEF(
"aq",
"aqmode", 1,
"AQ mode off/on");
104static const arg_def_t bitrates_arg =
105 ARG_DEF(
"bl",
"bitrates", 1,
106 "Bitrates[spatial_layer * num_temporal_layer + temporal_layer]");
107static const arg_def_t dropframe_thresh_arg =
108 ARG_DEF(NULL,
"drop-frame", 1,
"Temporal resampling threshold (buf %)");
109static const arg_def_t error_resilient_arg =
110 ARG_DEF(NULL,
"error-resilient", 1,
"Error resilient flag");
111static const arg_def_t output_obu_arg =
112 ARG_DEF(NULL,
"output-obu", 1,
113 "Write OBUs when set to 1. Otherwise write IVF files.");
114static const arg_def_t test_decode_arg =
115 ARG_DEF(NULL,
"test-decode", 1,
116 "Attempt to test decoding the output when set to 1. Default is 1.");
117static const arg_def_t psnr_arg =
118 ARG_DEF(NULL,
"psnr", -1,
"Show PSNR in status line.");
119static const arg_def_t ext_rc_arg =
120 ARG_DEF(NULL,
"use-ext-rc", 0,
"Use external rate control.");
121static const struct arg_enum_list tune_content_enum[] = {
122 {
"default", AOM_CONTENT_DEFAULT },
123 {
"screen", AOM_CONTENT_SCREEN },
124 {
"film", AOM_CONTENT_FILM },
127static const arg_def_t tune_content_arg = ARG_DEF_ENUM(
128 NULL,
"tune-content", 1,
"Tune content type", tune_content_enum);
130static const arg_def_t multilayer_metadata_file_arg =
131 ARG_DEF(
"ml",
"multilayer_metadata_file", 1,
132 "Experimental: path to multilayer metadata file");
135#if CONFIG_AV1_HIGHBITDEPTH
136static const struct arg_enum_list bitdepth_enum[] = { {
"8",
AOM_BITS_8 },
140static const arg_def_t bitdepth_arg = ARG_DEF_ENUM(
141 "d",
"bit-depth", 1,
"Bit depth for codec 8 or 10. ", bitdepth_enum);
144static const arg_def_t *svc_args[] = {
156 &temporal_layers_arg,
160#if CONFIG_AV1_HIGHBITDEPTH
165 &dropframe_thresh_arg,
166 &error_resilient_arg,
172 &multilayer_metadata_file_arg,
177#define zero(Dest) memset(&(Dest), 0, sizeof(Dest))
179static const char *exec_name;
181void usage_exit(
void) {
183 "Usage: %s <options> input_filename [input_filename ...] -o "
186 fprintf(stderr,
"Options:\n");
187 arg_show_usage(stderr, svc_args);
190 "Input files must be y4m or yuv.\n"
191 "If multiple input files are specified, they correspond to spatial "
192 "layers, and there should be as many as there are spatial layers.\n"
193 "All input files must have the same width, height, frame rate and number "
195 "If only one file is specified, it is used for all spatial layers.\n");
199static int file_is_y4m(
const char detect[4]) {
200 return memcmp(detect,
"YUV4", 4) == 0;
203static int fourcc_is_ivf(
const char detect[4]) {
204 if (memcmp(detect,
"DKIF", 4) == 0) {
210static const int option_max_values[ALL_OPTION_TYPES] = { 63, INT_MAX, INT_MAX,
213static const int option_min_values[ALL_OPTION_TYPES] = { 0, 0, 1, 0 };
215static void open_input_file(
struct AvxInputContext *input,
218 input->file = strcmp(input->filename,
"-") ? fopen(input->filename,
"rb")
219 : set_binary_mode(stdin);
221 if (!input->file) fatal(
"Failed to open input file");
223 if (!fseeko(input->file, 0, SEEK_END)) {
227 input->length = ftello(input->file);
232 input->pixel_aspect_ratio.numerator = 1;
233 input->pixel_aspect_ratio.denominator = 1;
238 input->detect.buf_read = fread(input->detect.buf, 1, 4, input->file);
239 input->detect.position = 0;
241 if (input->detect.buf_read == 4 && file_is_y4m(input->detect.buf)) {
242 if (y4m_input_open(&input->y4m, input->file, input->detect.buf, 4, csp,
243 input->only_i420) >= 0) {
244 input->file_type = FILE_TYPE_Y4M;
245 input->width = input->y4m.pic_w;
246 input->height = input->y4m.pic_h;
247 input->pixel_aspect_ratio.numerator = input->y4m.par_n;
248 input->pixel_aspect_ratio.denominator = input->y4m.par_d;
249 input->framerate.numerator = input->y4m.fps_n;
250 input->framerate.denominator = input->y4m.fps_d;
251 input->fmt = input->y4m.aom_fmt;
252 input->bit_depth = static_cast<aom_bit_depth_t>(input->y4m.bit_depth);
254 fatal(
"Unsupported Y4M stream.");
256 }
else if (input->detect.buf_read == 4 && fourcc_is_ivf(input->detect.buf)) {
257 fatal(
"IVF is not supported as input.");
259 input->file_type = FILE_TYPE_RAW;
263static aom_codec_err_t extract_option(LAYER_OPTION_TYPE type,
char *input,
264 int *value0,
int *value1) {
265 if (type == SCALE_FACTOR) {
266 *value0 = (int)strtol(input, &input, 10);
268 *value1 = (int)strtol(input, &input, 10);
270 if (*value0 < option_min_values[SCALE_FACTOR] ||
271 *value1 < option_min_values[SCALE_FACTOR] ||
272 *value0 > option_max_values[SCALE_FACTOR] ||
273 *value1 > option_max_values[SCALE_FACTOR] ||
277 *value0 = atoi(input);
278 if (*value0 < option_min_values[type] || *value0 > option_max_values[type])
286 int *option0,
int *option1) {
290 const char *delim =
",";
298 if (input == NULL || option0 == NULL ||
299 (option1 == NULL && type == SCALE_FACTOR))
302 const size_t input_length = strlen(input);
303 input_string =
reinterpret_cast<char *
>(malloc(input_length + 1));
305 memcpy(input_string, input, input_length + 1);
306 token = strtok(input_string, delim);
307 for (i = 0; i < num_layers; ++i) {
309 res = extract_option(type, token, option0 + i, option1 + i);
311 token = strtok(NULL, delim);
321static void parse_command_line(
int argc,
const char **argv_,
329 char string_options[1024] = { 0 };
334 app_input->layering_mode = 0;
335 app_input->output_obu = 0;
336 app_input->decode = 1;
341 argv = argv_dup(argc - 1, argv_ + 1);
343 fprintf(stderr,
"Error allocating argument list\n");
346 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
349 if (arg_match(&arg, &outputfile, argi)) {
350 app_input->output_filename = arg.val;
351 }
else if (arg_match(&arg, &width_arg, argi)) {
352 enc_cfg->
g_w = arg_parse_uint(&arg);
353 }
else if (arg_match(&arg, &height_arg, argi)) {
354 enc_cfg->
g_h = arg_parse_uint(&arg);
355 }
else if (arg_match(&arg, &timebase_arg, argi)) {
356 enc_cfg->
g_timebase = arg_parse_rational(&arg);
357 }
else if (arg_match(&arg, &bitrate_arg, argi)) {
359 }
else if (arg_match(&arg, &spatial_layers_arg, argi)) {
361 }
else if (arg_match(&arg, &temporal_layers_arg, argi)) {
363 }
else if (arg_match(&arg, &speed_arg, argi)) {
364 app_input->speed = arg_parse_uint(&arg);
365 if (app_input->speed > 11) {
366 aom_tools_warn(
"Mapping speed %d to speed 11.\n", app_input->speed);
368 }
else if (arg_match(&arg, &aqmode_arg, argi)) {
369 app_input->aq_mode = arg_parse_uint(&arg);
370 }
else if (arg_match(&arg, &threads_arg, argi)) {
371 enc_cfg->
g_threads = arg_parse_uint(&arg);
372 }
else if (arg_match(&arg, &layering_mode_arg, argi)) {
373 app_input->layering_mode = arg_parse_int(&arg);
374 }
else if (arg_match(&arg, &kf_dist_arg, argi)) {
377 }
else if (arg_match(&arg, &scale_factors_arg, argi)) {
381 app_input->scale_factors_explicitly_set =
true;
383 die(
"Failed to parse scale factors: %s\n",
386 }
else if (arg_match(&arg, &min_q_arg, argi)) {
388 }
else if (arg_match(&arg, &max_q_arg, argi)) {
390#if CONFIG_AV1_HIGHBITDEPTH
391 }
else if (arg_match(&arg, &bitdepth_arg, argi)) {
404 die(
"Error: Invalid bit depth selected (%d)\n", enc_cfg->
g_bit_depth);
407 }
else if (arg_match(&arg, &dropframe_thresh_arg, argi)) {
409 }
else if (arg_match(&arg, &error_resilient_arg, argi)) {
412 die(
"Invalid value for error resilient (0, 1): %d.",
414 }
else if (arg_match(&arg, &output_obu_arg, argi)) {
415 app_input->output_obu = arg_parse_uint(&arg);
416 if (app_input->output_obu != 0 && app_input->output_obu != 1)
417 die(
"Invalid value for obu output flag (0, 1): %d.",
418 app_input->output_obu);
419 }
else if (arg_match(&arg, &test_decode_arg, argi)) {
420 app_input->decode = arg_parse_uint(&arg);
421 if (app_input->decode != 0 && app_input->decode != 1)
422 die(
"Invalid value for test decode flag (0, 1): %d.",
424 }
else if (arg_match(&arg, &tune_content_arg, argi)) {
425 app_input->tune_content = arg_parse_enum_or_int(&arg);
426 printf(
"tune content %d\n", app_input->tune_content);
427 }
else if (arg_match(&arg, &psnr_arg, argi)) {
428 app_input->show_psnr = 1;
429 }
else if (arg_match(&arg, &ext_rc_arg, argi)) {
430 app_input->use_external_rc =
true;
432 }
else if (arg_match(&arg, &multilayer_metadata_file_arg, argi)) {
433 app_input->multilayer_metadata_file = arg.val;
441 for (argi = argj = argv; (*argj = *argi); argi += arg.argv_step) {
443 if (arg_match(&arg, &bitrates_arg, argi)) {
455 if (strlen(string_options) > 0)
456 strncpy(app_input->options, string_options, OPTION_BUFFER_SIZE);
459 for (argi = argv; *argi; ++argi)
460 if (argi[0][0] ==
'-' && strlen(argi[0]) > 1)
461 die(
"Error: Unrecognized option %s\n", *argi);
463 if (argv[0] == NULL) {
468 while (argv[input_count] != NULL && input_count < MAX_NUM_SPATIAL_LAYERS) {
469 app_input->input_ctx[input_count].filename = argv[input_count];
473 die(
"Error: Number of input files does not match number of spatial layers");
475 if (argv[input_count] != NULL) {
476 die(
"Error: Too many input files specified, there should be at most %d",
477 MAX_NUM_SPATIAL_LAYERS);
482 for (
int i = 0; i < input_count; ++i) {
484 if (app_input->input_ctx[i].file_type == FILE_TYPE_Y4M) {
485 if (enc_cfg->
g_w == 0 || enc_cfg->
g_h == 0) {
487 enc_cfg->
g_w = app_input->input_ctx[i].width;
488 enc_cfg->
g_h = app_input->input_ctx[i].height;
490 enc_cfg->
g_timebase.
num = app_input->input_ctx[i].framerate.denominator;
491 enc_cfg->
g_timebase.
den = app_input->input_ctx[i].framerate.numerator;
492 }
else if (enc_cfg->
g_w != app_input->input_ctx[i].width ||
493 enc_cfg->
g_h != app_input->input_ctx[i].height ||
495 app_input->input_ctx[i].framerate.denominator ||
497 app_input->input_ctx[i].framerate.numerator) {
498 die(
"Error: Input file dimensions and/or frame rate mismatch");
502 if (enc_cfg->
g_w == 0 || enc_cfg->
g_h == 0) {
503 die(
"Error: Input file dimensions not set, use -w and -h");
506 if (enc_cfg->
g_w < 16 || enc_cfg->
g_w % 2 || enc_cfg->
g_h < 16 ||
508 die(
"Invalid resolution: %d x %d\n", enc_cfg->
g_w, enc_cfg->
g_h);
513 "width %u, height: %u\n"
514 "num: %d, den: %d, bitrate: %u\n"
522static const int mode_to_num_temporal_layers[12] = {
523 1, 2, 3, 3, 2, 1, 1, 3, 3, 3, 3, 3,
525static const int mode_to_num_spatial_layers[12] = {
526 1, 1, 1, 1, 1, 2, 3, 2, 3, 3, 3, 3,
530struct RateControlMetrics {
547 double avg_st_encoding_bitrate;
549 double variance_st_encoding_bitrate;
557static const int REF_FRAMES = 8;
559static const int INTER_REFS_PER_FRAME = 7;
572static int read_frame(
struct AvxInputContext *input_ctx,
aom_image_t *img) {
573 FILE *f = input_ctx->file;
574 y4m_input *y4m = &input_ctx->y4m;
577 if (input_ctx->file_type == FILE_TYPE_Y4M) {
578 if (y4m_input_fetch_frame(y4m, f, img) < 1)
return 0;
580 shortread = read_yuv_frame(input_ctx, img);
586static void close_input_file(
struct AvxInputContext *input) {
588 if (input->file_type == FILE_TYPE_Y4M) y4m_input_close(&input->y4m);
597static void set_rate_control_metrics(
struct RateControlMetrics *rc,
598 double framerate,
int ss_number_layers,
599 int ts_number_layers) {
601 ts_rate_decimator[0] = 1;
602 if (ts_number_layers == 2) {
603 ts_rate_decimator[0] = 2;
604 ts_rate_decimator[1] = 1;
606 if (ts_number_layers == 3) {
607 ts_rate_decimator[0] = 4;
608 ts_rate_decimator[1] = 2;
609 ts_rate_decimator[2] = 1;
613 for (
int sl = 0; sl < ss_number_layers; ++sl) {
614 int i = sl * ts_number_layers;
615 rc->layer_framerate[0] = framerate / ts_rate_decimator[0];
617 1000.0 * rc->layer_target_bitrate[i] / rc->layer_framerate[0];
618 for (
int tl = 0; tl < ts_number_layers; ++tl) {
619 i = sl * ts_number_layers + tl;
621 rc->layer_framerate[tl] = framerate / ts_rate_decimator[tl];
624 (rc->layer_target_bitrate[i] - rc->layer_target_bitrate[i - 1]) /
625 (rc->layer_framerate[tl] - rc->layer_framerate[tl - 1]);
627 rc->layer_input_frames[tl] = 0;
628 rc->layer_enc_frames[tl] = 0;
629 rc->layer_encoding_bitrate[i] = 0.0;
630 rc->layer_avg_frame_size[i] = 0.0;
631 rc->layer_avg_rate_mismatch[i] = 0.0;
634 rc->window_count = 0;
635 rc->window_size = 15;
636 rc->avg_st_encoding_bitrate = 0.0;
637 rc->variance_st_encoding_bitrate = 0.0;
640static void printout_rate_control_summary(
struct RateControlMetrics *rc,
641 int frame_cnt,
int ss_number_layers,
642 int ts_number_layers) {
643 int tot_num_frames = 0;
644 double perc_fluctuation = 0.0;
645 printf(
"Total number of processed frames: %d\n\n", frame_cnt - 1);
646 printf(
"Rate control layer stats for %d layer(s):\n\n", ts_number_layers);
647 for (
int sl = 0; sl < ss_number_layers; ++sl) {
649 for (
int tl = 0; tl < ts_number_layers; ++tl) {
650 int i = sl * ts_number_layers + tl;
651 const int num_dropped =
652 tl > 0 ? rc->layer_input_frames[tl] - rc->layer_enc_frames[tl]
653 : rc->layer_input_frames[tl] - rc->layer_enc_frames[tl] - 1;
654 tot_num_frames += rc->layer_input_frames[tl];
655 rc->layer_encoding_bitrate[i] = 0.001 * rc->layer_framerate[tl] *
656 rc->layer_encoding_bitrate[i] /
658 rc->layer_avg_frame_size[i] =
659 rc->layer_avg_frame_size[i] / rc->layer_enc_frames[tl];
660 rc->layer_avg_rate_mismatch[i] =
661 100.0 * rc->layer_avg_rate_mismatch[i] / rc->layer_enc_frames[tl];
662 printf(
"For layer#: %d %d \n", sl, tl);
663 printf(
"Bitrate (target vs actual): %d %f\n", rc->layer_target_bitrate[i],
664 rc->layer_encoding_bitrate[i]);
665 printf(
"Average frame size (target vs actual): %f %f\n", rc->layer_pfb[i],
666 rc->layer_avg_frame_size[i]);
667 printf(
"Average rate_mismatch: %f\n", rc->layer_avg_rate_mismatch[i]);
669 "Number of input frames, encoded (non-key) frames, "
670 "and perc dropped frames: %d %d %f\n",
671 rc->layer_input_frames[tl], rc->layer_enc_frames[tl],
672 100.0 * num_dropped / rc->layer_input_frames[tl]);
676 rc->avg_st_encoding_bitrate = rc->avg_st_encoding_bitrate / rc->window_count;
677 rc->variance_st_encoding_bitrate =
678 rc->variance_st_encoding_bitrate / rc->window_count -
679 (rc->avg_st_encoding_bitrate * rc->avg_st_encoding_bitrate);
680 perc_fluctuation = 100.0 * sqrt(rc->variance_st_encoding_bitrate) /
681 rc->avg_st_encoding_bitrate;
682 printf(
"Short-time stats, for window of %d frames:\n", rc->window_size);
683 printf(
"Average, rms-variance, and percent-fluct: %f %f %f\n",
684 rc->avg_st_encoding_bitrate, sqrt(rc->variance_st_encoding_bitrate),
686 if (frame_cnt - 1 != tot_num_frames)
687 die(
"Error: Number of input frames not equal to output!\n");
691static void set_layer_pattern(
695 int spatial_layer_id,
int is_key_frame,
int ksvc_mode,
int speed,
696 int *reference_updated,
int test_roi_map) {
699 int use_rps_example = 0;
701 int enable_longterm_temporal_ref = 1;
702 int shift = (layering_mode == 8) ? 2 : 0;
703 int simulcast_mode = (layering_mode == 11);
704 *use_svc_control = 1;
707 int base_count = superframe_cnt >> 2;
714 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
ref_idx[i] = i;
715 for (i = 0; i < INTER_REFS_PER_FRAME; i++) ref_frame_config->
reference[i] = 0;
716 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->
refresh[i] = 0;
723 switch (layering_mode) {
725 if (use_rps_example == 0) {
729 ref_frame_config->
refresh[0] = 1;
730 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
733 if (test_roi_map) ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
741 int last_idx_refresh = 0;
750 if (superframe_cnt > 1) last_idx = (superframe_cnt - 1) % sh;
752 last_idx_refresh = superframe_cnt % sh;
754 if (superframe_cnt > lag_gld) gld_idx = (superframe_cnt - lag_gld) % sh;
756 if (superframe_cnt > lag_alt)
757 alt_ref_idx = (superframe_cnt - lag_alt) % sh;
760 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
761 ref_frame_config->
ref_idx[i] = last_idx;
763 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = last_idx;
764 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = last_idx_refresh;
765 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = gld_idx;
766 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = alt_ref_idx;
768 ref_frame_config->
refresh[last_idx_refresh] = 1;
770 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
771 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
772 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
774 if (superframe_cnt % 200 == 0 && superframe_cnt > 0) {
775 ref_frame_config->
reference[SVC_LAST_FRAME] = 0;
776 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 0;
777 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
781 if (superframe_cnt % 400 == 0 && superframe_cnt > 0) {
782 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = gld_idx;
783 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
784 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 0;
785 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 0;
795 base_count = superframe_cnt >> 1;
796 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
799 if (base_count > 0) {
800 lag_index = 5 + (base_count % 3);
801 if (superframe_cnt % 2 != 0) lag_index = 5 + ((base_count + 1) % 3);
804 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = lag_index;
805 if (superframe_cnt % 2 == 0) {
808 ref_frame_config->
refresh[0] = 1;
809 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
811 ref_frame_config->
refresh[lag_index] = 1;
813 if (base_count % 32 == 0) ref_frame_config->
refresh[3] = 1;
817 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
821 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
822 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
830 if (superframe_cnt % 4 == 0) {
834 ref_frame_config->
refresh[0] = 1;
835 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
836 }
else if ((superframe_cnt - 1) % 4 == 0) {
839 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
840 }
else if ((superframe_cnt - 2) % 4 == 0) {
843 ref_frame_config->
refresh[1] = 1;
844 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
845 }
else if ((superframe_cnt - 3) % 4 == 0) {
850 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
851 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
852 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
863 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
866 if (base_count > 0) {
867 lag_index = 5 + (base_count % 3);
868 if (superframe_cnt % 4 != 0) lag_index = 5 + ((base_count + 1) % 3);
871 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = lag_index;
872 if (superframe_cnt % 4 == 0) {
876 ref_frame_config->
refresh[0] = 1;
877 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
879 if (base_count % 10 == 0) ref_frame_config->
refresh[3] = 1;
881 ref_frame_config->
refresh[lag_index] = 1;
882 }
else if ((superframe_cnt - 1) % 4 == 0) {
885 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
886 }
else if ((superframe_cnt - 2) % 4 == 0) {
889 ref_frame_config->
refresh[1] = 1;
890 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
891 }
else if ((superframe_cnt - 3) % 4 == 0) {
896 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
897 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 0;
898 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
901 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
902 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
915 if (superframe_cnt % 4 == 0) {
919 ref_frame_config->
refresh[0] = 1;
920 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
921 }
else if ((superframe_cnt - 1) % 4 == 0) {
924 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
925 }
else if ((superframe_cnt - 2) % 4 == 0) {
928 ref_frame_config->
refresh[3] = 1;
929 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
930 }
else if ((superframe_cnt - 3) % 4 == 0) {
933 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
956 ref_frame_config->
refresh[0] = 1;
957 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
958 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 2;
959 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
963 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
964 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 0;
965 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 2;
966 ref_frame_config->
refresh[1] = 1;
967 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
968 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
981 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
982 ref_frame_config->
ref_idx[i] = 0;
983 ref_frame_config->
refresh[0] = 1;
984 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
989 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
990 ref_frame_config->
ref_idx[i] = 0;
991 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
992 ref_frame_config->
refresh[1] = 1;
993 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
994 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
999 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1000 ref_frame_config->
ref_idx[i] = 1;
1001 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1002 ref_frame_config->
refresh[2] = 1;
1003 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1004 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
1007 if (enable_longterm_temporal_ref) {
1008 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
1009 ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
1010 if (base_count % 10 == 0)
1011 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
1017 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1018 if (superframe_cnt % 4 == 0) {
1024 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1025 ref_frame_config->
ref_idx[i] = 0;
1026 ref_frame_config->
refresh[0] = 1;
1029 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1030 ref_frame_config->
ref_idx[i] = 0;
1031 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1032 ref_frame_config->
refresh[1] = 1;
1034 }
else if ((superframe_cnt - 1) % 4 == 0) {
1038 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1039 ref_frame_config->
ref_idx[i] = 0;
1040 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1041 ref_frame_config->
refresh[3] = 1;
1046 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1047 ref_frame_config->
ref_idx[i] = 3;
1048 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1050 }
else if ((superframe_cnt - 2) % 4 == 0) {
1057 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1058 ref_frame_config->
ref_idx[i] = 0;
1059 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
1060 ref_frame_config->
refresh[5 - shift] = 1;
1065 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1066 ref_frame_config->
ref_idx[i] = 5 - shift;
1067 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1068 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
1069 ref_frame_config->
refresh[6 - shift] = 1;
1071 }
else if ((superframe_cnt - 3) % 4 == 0) {
1078 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1079 ref_frame_config->
ref_idx[i] = 0;
1080 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
1081 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1082 ref_frame_config->
refresh[3] = 1;
1086 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1087 ref_frame_config->
ref_idx[i] = 0;
1088 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
1089 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1106 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1107 if (superframe_cnt % 4 == 0) {
1113 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1114 ref_frame_config->
ref_idx[i] = 0;
1115 ref_frame_config->
refresh[0] = 1;
1120 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1121 ref_frame_config->
ref_idx[i] = 0;
1122 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1123 ref_frame_config->
refresh[1] = 1;
1128 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1129 ref_frame_config->
ref_idx[i] = 1;
1130 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1131 ref_frame_config->
refresh[2] = 1;
1133 }
else if ((superframe_cnt - 1) % 4 == 0) {
1140 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1141 ref_frame_config->
ref_idx[i] = 0;
1142 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1143 ref_frame_config->
refresh[3] = 1;
1148 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1149 ref_frame_config->
ref_idx[i] = 3;
1150 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1151 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
1152 ref_frame_config->
refresh[4] = 1;
1157 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1158 ref_frame_config->
ref_idx[i] = 4;
1159 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1161 }
else if ((superframe_cnt - 2) % 4 == 0) {
1168 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1169 ref_frame_config->
ref_idx[i] = 0;
1170 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5 - shift;
1171 ref_frame_config->
refresh[5 - shift] = 1;
1176 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1177 ref_frame_config->
ref_idx[i] = 5 - shift;
1178 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1179 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 6 - shift;
1180 ref_frame_config->
refresh[6 - shift] = 1;
1185 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1186 ref_frame_config->
ref_idx[i] = 6 - shift;
1187 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1188 ref_frame_config->
ref_idx[SVC_LAST3_FRAME] = 7 - shift;
1189 ref_frame_config->
refresh[7 - shift] = 1;
1191 }
else if ((superframe_cnt - 3) % 4 == 0) {
1198 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1199 ref_frame_config->
ref_idx[i] = 0;
1200 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5 - shift;
1201 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1202 ref_frame_config->
refresh[3] = 1;
1206 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1207 ref_frame_config->
ref_idx[i] = 0;
1208 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 6 - shift;
1209 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1210 ref_frame_config->
ref_idx[SVC_LAST2_FRAME] = 4;
1211 ref_frame_config->
refresh[4] = 1;
1215 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1216 ref_frame_config->
ref_idx[i] = 0;
1217 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 7 - shift;
1218 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 4;
1241 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1244 for (i = 0; i < REF_FRAMES; i++) ref_frame_config->
refresh[i] = 0;
1245 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1246 ref_frame_config->
ref_idx[i] = 0;
1253 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1254 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 1;
1255 ref_frame_config->
refresh[0] = 1;
1256 ref_frame_config->
refresh[1] = 1;
1261 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1262 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 3;
1263 ref_frame_config->
refresh[2] = 1;
1264 ref_frame_config->
refresh[3] = 1;
1269 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1270 ref_frame_config->
ref_idx[SVC_GOLDEN_FRAME] = 5;
1271 ref_frame_config->
refresh[4] = 1;
1272 ref_frame_config->
refresh[5] = 1;
1274 }
else if (superframe_cnt % 4 == 0) {
1281 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1282 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1283 ref_frame_config->
ref_idx[i] = 1;
1284 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1285 ref_frame_config->
refresh[0] = 1;
1290 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1291 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1292 ref_frame_config->
ref_idx[i] = 3;
1293 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1294 ref_frame_config->
refresh[2] = 1;
1299 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1300 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1301 ref_frame_config->
ref_idx[i] = 5;
1302 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1303 ref_frame_config->
refresh[4] = 1;
1305 }
else if ((superframe_cnt - 1) % 4 == 0) {
1311 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1312 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1313 ref_frame_config->
ref_idx[i] = 1;
1314 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1318 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1319 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1320 ref_frame_config->
ref_idx[i] = 3;
1321 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1325 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1326 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1327 ref_frame_config->
ref_idx[i] = 5;
1328 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1330 }
else if ((superframe_cnt - 2) % 4 == 0) {
1337 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1338 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1339 ref_frame_config->
ref_idx[i] = 1;
1340 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 0;
1341 ref_frame_config->
refresh[1] = 1;
1346 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1347 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1348 ref_frame_config->
ref_idx[i] = 3;
1349 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 2;
1350 ref_frame_config->
refresh[3] = 1;
1355 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1356 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1357 ref_frame_config->
ref_idx[i] = 5;
1358 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 4;
1359 ref_frame_config->
refresh[5] = 1;
1361 }
else if ((superframe_cnt - 3) % 4 == 0) {
1367 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1368 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1369 ref_frame_config->
ref_idx[i] = 0;
1370 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 1;
1374 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1375 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1376 ref_frame_config->
ref_idx[i] = 2;
1377 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 3;
1381 ref_frame_config->
reference[SVC_LAST_FRAME] = 1;
1382 for (i = 0; i < INTER_REFS_PER_FRAME; i++)
1383 ref_frame_config->
ref_idx[i] = 4;
1384 ref_frame_config->
ref_idx[SVC_LAST_FRAME] = 5;
1389 ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 1;
1393 if (!is_key_frame) ref_frame_config->
reference[SVC_GOLDEN_FRAME] = 0;
1398 ref_frame_config->
reference[SVC_LAST_FRAME] = 0;
1405 if (!simulcast_mode && enable_longterm_temporal_ref &&
1407 ref_frame_config->
ref_idx[SVC_ALTREF_FRAME] = REF_FRAMES - 1;
1408 if (!is_key_frame) ref_frame_config->
reference[SVC_ALTREF_FRAME] = 1;
1410 ref_frame_config->
refresh[REF_FRAMES - 1] = 1;
1413 default: assert(0); die(
"Error: Unsupported temporal layering mode!\n");
1415 for (i = 0; i < REF_FRAMES; i++) {
1416 if (ref_frame_config->
refresh[i] == 1) {
1417 *reference_updated = 1;
1423static void write_literal(
struct aom_write_bit_buffer *wb, uint32_t data,
1424 uint8_t bits, uint32_t offset = 0) {
1426 die(
"Invalid bits value %d > 32\n", bits);
1428 const uint32_t max =
static_cast<uint32_t
>(((uint64_t)1 << bits) - 1);
1429 if (data < offset || (data - offset) > max) {
1430 die(
"Invalid data, value %u out of range [%u, %" PRIu64
"]\n", data, offset,
1431 (uint64_t)max + offset);
1433 aom_wb_write_unsigned_literal(wb, data - offset, bits);
1436static void write_depth_representation_element(
1437 struct aom_write_bit_buffer *buffer,
1438 const std::pair<libaom_examples::DepthRepresentationElement, bool>
1440 if (!element.second) {
1443 write_literal(buffer, element.first.sign_flag, 1);
1444 write_literal(buffer, element.first.exponent, 7);
1445 if (element.first.mantissa_len == 0 || element.first.mantissa_len > 32) {
1446 die(
"Invalid mantissan_len %d\n", element.first.mantissa_len);
1448 write_literal(buffer, element.first.mantissa_len - 1, 5);
1449 write_literal(buffer, element.first.mantissa, element.first.mantissa_len);
1452static void write_color_properties(
1453 struct aom_write_bit_buffer *buffer,
1454 const std::pair<libaom_examples::ColorProperties, bool> &color_properties) {
1455 write_literal(buffer, color_properties.second, 1);
1456 if (color_properties.second) {
1457 write_literal(buffer, color_properties.first.color_range, 1);
1458 write_literal(buffer, color_properties.first.color_primaries, 8);
1459 write_literal(buffer, color_properties.first.transfer_characteristics, 8);
1460 write_literal(buffer, color_properties.first.matrix_coefficients, 8);
1462 write_literal(buffer, 0, 1);
1466static void write_alpha_information(
1467 struct aom_write_bit_buffer *buffer,
1468 const libaom_examples::AlphaInformation &alpha_info) {
1469 write_literal(buffer, alpha_info.alpha_use_idc, 2);
1470 write_literal(buffer, alpha_info.alpha_simple_flag, 1);
1471 if (!alpha_info.alpha_simple_flag) {
1472 write_literal(buffer, alpha_info.alpha_bit_depth, 3, 8);
1473 write_literal(buffer, alpha_info.alpha_clip_idc, 2);
1474 write_literal(buffer, alpha_info.alpha_incr_flag, 1);
1475 write_literal(buffer, alpha_info.alpha_transparent_value,
1476 alpha_info.alpha_bit_depth + 1);
1477 write_literal(buffer, alpha_info.alpha_opaque_value,
1478 alpha_info.alpha_bit_depth + 1);
1479 if (buffer->bit_offset % 8 != 0) {
1481 write_literal(buffer, 0, 8 - (buffer->bit_offset % 8));
1483 assert(buffer->bit_offset % 8 == 0);
1485 write_literal(buffer, 0, 6);
1486 write_color_properties(buffer, alpha_info.alpha_color_description);
1488 write_literal(buffer, 0, 5);
1492static void write_depth_information(
1493 struct aom_write_bit_buffer *buffer,
1494 const libaom_examples::DepthInformation &depth_info) {
1495 write_literal(buffer, depth_info.z_near.second, 1);
1496 write_literal(buffer, depth_info.z_far.second, 1);
1497 write_literal(buffer, depth_info.d_min.second, 1);
1498 write_literal(buffer, depth_info.d_max.second, 1);
1499 write_literal(buffer, depth_info.depth_representation_type, 4);
1500 if (depth_info.d_min.second || depth_info.d_max.second) {
1501 write_literal(buffer, depth_info.disparity_ref_view_id, 2);
1503 write_depth_representation_element(buffer, depth_info.z_near);
1504 write_depth_representation_element(buffer, depth_info.z_far);
1505 write_depth_representation_element(buffer, depth_info.d_min);
1506 write_depth_representation_element(buffer, depth_info.d_max);
1507 if (buffer->bit_offset % 8 != 0) {
1508 write_literal(buffer, 0, 8 - (buffer->bit_offset % 8));
1512static void add_multilayer_metadata(
1513 aom_image_t *frame,
const libaom_examples::MultilayerMetadata &multilayer,
1514 int frame_idx,
int spatial_id) {
1518 std::vector<uint8_t> data(1024);
1519 struct aom_write_bit_buffer buffer = { data.data(), 0 };
1521 write_literal(&buffer, multilayer.use_case, 6);
1522 if (multilayer.layers.empty()) {
1523 die(
"Invalid multilayer metadata, no layers found\n");
1524 }
else if (multilayer.layers.size() > MAX_NUM_SPATIAL_LAYERS) {
1525 die(
"Invalid multilayer metadata, too many layers (max is %d)\n",
1526 MAX_NUM_SPATIAL_LAYERS);
1528 write_literal(&buffer, (
int)multilayer.layers.size() - 1, 2);
1529 assert(buffer.bit_offset % 8 == 0);
1530 for (
size_t i = 0; i < multilayer.layers.size(); ++i) {
1531 const libaom_examples::LayerMetadata &layer = multilayer.layers[i];
1534 const int bytes_reserved_for_size = 3;
1536 write_literal(&buffer, 0, bytes_reserved_for_size * 8);
1537 const uint32_t metadata_start = buffer.bit_offset;
1538 write_literal(&buffer, (
int)i, 2);
1539 write_literal(&buffer, layer.layer_type, 5);
1540 write_literal(&buffer, layer.luma_plane_only_flag, 1);
1541 write_literal(&buffer, layer.layer_view_type, 3);
1542 write_literal(&buffer, layer.group_id, 2);
1543 write_literal(&buffer, layer.layer_dependency_idc, 3);
1544 write_literal(&buffer, layer.layer_metadata_scope, 2);
1545 write_literal(&buffer, 0, 4);
1548 write_color_properties(&buffer, layer.layer_color_description);
1550 write_literal(&buffer, 0, 2);
1552 assert(buffer.bit_offset % 8 == 0);
1554 if (layer.layer_type == libaom_examples::MULTILAYER_LAYER_TYPE_ALPHA &&
1555 layer.layer_metadata_scope >= libaom_examples::SCOPE_GLOBAL) {
1556 write_alpha_information(&buffer, layer.alpha);
1557 assert(buffer.bit_offset % 8 == 0);
1558 }
else if (layer.layer_type ==
1559 libaom_examples::MULTILAYER_LAYER_TYPE_DEPTH &&
1560 layer.layer_metadata_scope >= libaom_examples::SCOPE_GLOBAL) {
1561 write_depth_information(&buffer, layer.depth);
1562 assert(buffer.bit_offset % 8 == 0);
1565 assert(buffer.bit_offset % 8 == 0);
1567 const int metadata_size_bytes = (buffer.bit_offset - metadata_start) / 8;
1568 const uint8_t size_pos = metadata_start / 8 - bytes_reserved_for_size;
1570 if (aom_uleb_encode_fixed_size(metadata_size_bytes, bytes_reserved_for_size,
1571 bytes_reserved_for_size,
1572 &buffer.bit_buffer[size_pos], &coded_size)) {
1574 die(
"Error: Failed to write metadata size\n");
1577 assert(buffer.bit_offset % 8 == 0);
1579 buffer.bit_buffer, buffer.bit_offset / 8,
1581 die(
"Error: Failed to add metadata\n");
1584 if ((
int)multilayer.layers.size() > spatial_id) {
1585 const libaom_examples::LayerMetadata &layer = multilayer.layers[spatial_id];
1586 for (
const libaom_examples::FrameLocalMetadata &local_metadata :
1587 layer.local_metadata) {
1588 if (local_metadata.frame_idx == frame_idx) {
1589 if (layer.layer_type == libaom_examples::MULTILAYER_LAYER_TYPE_ALPHA) {
1590 buffer = { data.data(), 0 };
1591 write_alpha_information(&buffer, local_metadata.alpha);
1594 buffer.bit_buffer, buffer.bit_offset / 8,
1596 die(
"Error: Failed to add metadata\n");
1598 }
else if (layer.layer_type ==
1599 libaom_examples::MULTILAYER_LAYER_TYPE_DEPTH) {
1600 buffer = { data.data(), 0 };
1601 write_depth_information(&buffer, local_metadata.depth);
1604 buffer.bit_buffer, buffer.bit_offset / 8,
1606 die(
"Error: Failed to add metadata\n");
1615#if CONFIG_AV1_DECODER
1619 const int frames_out) {
1627#if CONFIG_AV1_HIGHBITDEPTH
1635 enc_img.
d_w, enc_img.
d_h, 16);
1636 aom_img_truncate_16_to_8(&enc_hbd_img, &enc_img);
1637 enc_img = enc_hbd_img;
1644 dec_img.
d_w, dec_img.
d_h, 16);
1645 aom_img_truncate_16_to_8(&dec_hbd_img, &dec_img);
1646 dec_img = dec_hbd_img;
1651 if (!aom_compare_img(&enc_img, &dec_img)) {
1652 int y[4], u[4], v[4];
1653#if CONFIG_AV1_HIGHBITDEPTH
1655 aom_find_mismatch_high(&enc_img, &dec_img, y, u, v);
1657 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1660 aom_find_mismatch(&enc_img, &dec_img, y, u, v);
1663 "Encode/decode mismatch on frame %d at"
1664 " Y[%d, %d] {%d/%d},"
1665 " U[%d, %d] {%d/%d},"
1666 " V[%d, %d] {%d/%d}\n",
1667 frames_out, y[0], y[1], y[2], y[3], u[0], u[1], u[2], u[3], v[0],
1680 uint64_t psnr_sse_total[2];
1681 uint64_t psnr_samples_total[2];
1682 double psnr_totals[2][4];
1686static void show_psnr(
struct psnr_stats *psnr_stream,
double peak) {
1689 if (!psnr_stream->psnr_count[0])
return;
1691 fprintf(stderr,
"\nPSNR (Overall/Avg/Y/U/V)");
1692 ovpsnr = sse_to_psnr((
double)psnr_stream->psnr_samples_total[0], peak,
1693 (
double)psnr_stream->psnr_sse_total[0]);
1694 fprintf(stderr,
" %.3f", ovpsnr);
1696 for (
int i = 0; i < 4; i++) {
1697 fprintf(stderr,
" %.3f",
1698 psnr_stream->psnr_totals[0][i] / psnr_stream->psnr_count[0]);
1700 fprintf(stderr,
"\n");
1703static aom::AV1RateControlRtcConfig create_rtc_rc_config(
1705 aom::AV1RateControlRtcConfig rc_cfg;
1706 rc_cfg.width = cfg.
g_w;
1707 rc_cfg.height = cfg.
g_h;
1717 rc_cfg.max_intra_bitrate_pct = 300;
1720 rc_cfg.ss_number_layers = 1;
1721 rc_cfg.ts_number_layers = 1;
1722 rc_cfg.scaling_factor_num[0] = 1;
1723 rc_cfg.scaling_factor_den[0] = 1;
1724 rc_cfg.layer_target_bitrate[0] =
static_cast<int>(rc_cfg.target_bandwidth);
1725 rc_cfg.max_quantizers[0] = rc_cfg.max_quantizer;
1726 rc_cfg.min_quantizers[0] = rc_cfg.min_quantizer;
1727 rc_cfg.aq_mode = app_input.aq_mode;
1732static int qindex_to_quantizer(
int qindex) {
1735 static const int quantizer_to_qindex[] = {
1736 0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48,
1737 52, 56, 60, 64, 68, 72, 76, 80, 84, 88, 92, 96, 100,
1738 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 144, 148, 152,
1739 156, 160, 164, 168, 172, 176, 180, 184, 188, 192, 196, 200, 204,
1740 208, 212, 216, 220, 224, 228, 232, 236, 240, 244, 249, 255,
1742 for (
int quantizer = 0; quantizer < 64; ++quantizer)
1743 if (quantizer_to_qindex[quantizer] >= qindex)
return quantizer;
1752 map.
rows = (cfg->
g_h + 15) / 16;
1753 map.
cols = (cfg->
g_w + 15) / 16;
1756 if (!map.
active_map) die(
"Failed to allocate active map");
1759 for (
unsigned int i = 0; i < map.
rows; ++i) {
1760 for (
unsigned int j = 0; j < map.
cols; ++j) {
1761 int index = map.
cols * i + j;
1763 if (frame_cnt < 300) {
1765 }
else if (frame_cnt >= 300) {
1766 if (i < map.rows / 2 && j >= map.
cols / 2) map.
active_map[index] = 0;
1772 die_codec(codec,
"Failed to set active map");
1780 const int block_size = 4;
1781 roi.
rows = (cfg->
g_h + block_size - 1) / block_size;
1782 roi.
cols = (cfg->
g_w + block_size - 1) / block_size;
1783 memset(&roi.
skip, 0,
sizeof(roi.
skip));
1791 for (
unsigned int i = 0; i < roi.
rows; ++i) {
1792 for (
unsigned int j = 0; j < roi.
cols; ++j) {
1793 const int idx = i * roi.
cols + j;
1794 if (i > roi.
rows / 4 && i < (3 * roi.
rows) / 4 && j > roi.
cols / 4 &&
1795 j < (3 * roi.
cols) / 4)
1802 if (roi_feature == kSkip)
1804 else if (roi_feature == kDeltaQ)
1806 else if (roi_feature == kDeltaLF)
1808 else if (roi_feature == kReference)
1812 die_codec(codec,
"Failed to set roi map");
1816int main(
int argc,
const char **argv) {
1820 AvxVideoWriter *total_layer_file = NULL;
1821 FILE *total_layer_obu_file = NULL;
1830 int frame_duration = 1;
1836#if CONFIG_INTERNAL_STATS
1837 FILE *stats_file = fopen(
"opsnr.stt",
"a");
1838 if (stats_file == NULL) {
1839 die(
"Cannot open opsnr.stt\n");
1842#if CONFIG_AV1_DECODER
1846 struct RateControlMetrics rc;
1847 int64_t cx_time = 0;
1850 double sum_bitrate = 0.0;
1851 double sum_bitrate2 = 0.0;
1852 double framerate = 30.0;
1853 int use_svc_control = 1;
1854 int set_err_resil_frame = 0;
1855 int test_changing_bitrate = 0;
1856 zero(rc.layer_target_bitrate);
1858 memset(&app_input, 0,
sizeof(AppInput));
1859 memset(&svc_params, 0,
sizeof(svc_params));
1863 const int test_dynamic_scaling_single_layer = 0;
1866 const int test_speed_per_layer = 0;
1869 const int test_active_maps = 0;
1872 const int test_roi_map = 0;
1875 for (i = 0; i < MAX_NUM_SPATIAL_LAYERS; ++i) {
1876 app_input.input_ctx[i].framerate.numerator = 30;
1877 app_input.input_ctx[i].framerate.denominator = 1;
1878 app_input.input_ctx[i].only_i420 = 0;
1879 app_input.input_ctx[i].bit_depth =
AOM_BITS_8;
1881 app_input.speed = 7;
1882 exec_name = argv[0];
1917 parse_command_line(argc, argv, &app_input, &svc_params, &cfg);
1922 unsigned int width = cfg.
g_w;
1923 unsigned int height = cfg.
g_h;
1925 if (app_input.layering_mode >= 0) {
1926 if (ts_number_layers !=
1927 mode_to_num_temporal_layers[app_input.layering_mode] ||
1929 mode_to_num_spatial_layers[app_input.layering_mode]) {
1930 die(
"Number of layers doesn't match layering mode.");
1934 bool has_non_y4m_input =
false;
1936 if (app_input.input_ctx[i].file_type != FILE_TYPE_Y4M) {
1937 has_non_y4m_input =
true;
1942 if (has_non_y4m_input) {
1944 die(
"Failed to allocate image (%dx%d)", width, height);
1953 unsigned int total_rate = 0;
1954 for (i = 0; i < ss_number_layers; i++) {
1960 die(
"Incorrect total target bitrate, expected: %d", total_rate);
1964 if (ts_number_layers == 2) {
1967 }
else if (ts_number_layers == 3) {
1973 libaom_examples::MultilayerMetadata multilayer_metadata;
1974 if (app_input.multilayer_metadata_file != NULL) {
1975 if (!libaom_examples::parse_multilayer_file(
1976 app_input.multilayer_metadata_file, &multilayer_metadata)) {
1977 die(
"Failed to parse multilayer metadata");
1979 libaom_examples::print_multilayer_metadata(multilayer_metadata);
1983 set_rate_control_metrics(&rc, framerate, ss_number_layers, ts_number_layers);
1986 info.codec_fourcc = get_fourcc_by_aom_encoder(encoder);
1987 info.frame_width = cfg.
g_w;
1988 info.frame_height = cfg.
g_h;
1992 for (
int sl = 0; sl < ss_number_layers; ++sl) {
1993 for (
int tl = 0; tl < ts_number_layers; ++tl) {
1994 i = sl * ts_number_layers + tl;
1995 char file_name[PATH_MAX];
1996 snprintf(file_name,
sizeof(file_name),
"%s_%d.av1",
1997 app_input.output_filename, i);
1998 if (app_input.output_obu) {
1999 obu_files[i] = fopen(file_name,
"wb");
2000 if (!obu_files[i]) die(
"Failed to open %s for writing", file_name);
2002 outfile[i] = aom_video_writer_open(file_name, kContainerIVF, &info);
2003 if (!outfile[i]) die(
"Failed to open %s for writing", file_name);
2007 if (app_input.output_obu) {
2008 total_layer_obu_file = fopen(app_input.output_filename,
"wb");
2009 if (!total_layer_obu_file)
2010 die(
"Failed to open %s for writing", app_input.output_filename);
2013 aom_video_writer_open(app_input.output_filename, kContainerIVF, &info);
2014 if (!total_layer_file)
2015 die(
"Failed to open %s for writing", app_input.output_filename);
2024 die_codec(&codec,
"Failed to initialize encoder");
2026#if CONFIG_AV1_DECODER
2027 if (app_input.decode) {
2029 die_codec(&decoder,
"Failed to initialize decoder");
2067 if (app_input.tune_content == AOM_CONTENT_SCREEN) {
2073 if (app_input.use_external_rc) {
2086 for (i = 0; i < ss_number_layers * ts_number_layers; ++i) {
2096 if (!app_input.scale_factors_explicitly_set) {
2097 for (i = 0; i < ss_number_layers; ++i) {
2101 if (ss_number_layers == 2) {
2104 }
else if (ss_number_layers == 3) {
2118 const int max_intra_size_pct = 300;
2120 max_intra_size_pct);
2123 for (
int lx = 0; lx < ts_number_layers * ss_number_layers; lx++) {
2124 cx_time_layer[lx] = 0;
2125 frame_cnt_layer[lx] = 0;
2128 std::unique_ptr<aom::AV1RateControlRTC> rc_api;
2129 if (app_input.use_external_rc) {
2130 const aom::AV1RateControlRtcConfig rc_cfg =
2131 create_rtc_rc_config(cfg, app_input);
2132 rc_api = aom::AV1RateControlRTC::Create(rc_cfg);
2136 struct psnr_stats psnr_stream;
2137 memset(&psnr_stream, 0,
sizeof(psnr_stream));
2138 while (frame_avail || got_data) {
2139 struct aom_usec_timer timer;
2140 frame_avail = read_frame(&(app_input.input_ctx[0]), &raw);
2142 for (
int slx = 0; slx < ss_number_layers; slx++) {
2143 if (slx > 0 && app_input.input_ctx[slx].filename != NULL) {
2144 const int previous_layer_frame_avail = frame_avail;
2145 frame_avail = read_frame(&(app_input.input_ctx[slx]), &raw);
2146 if (previous_layer_frame_avail != frame_avail) {
2147 die(
"Mismatch in number of frames between spatial layer input files");
2153 int reference_updated = 0;
2156 int is_key_frame = (frame_cnt % cfg.
kf_max_dist) == 0;
2158 if (app_input.layering_mode >= 0) {
2161 set_layer_pattern(app_input.layering_mode, frame_cnt, &layer_id,
2162 &ref_frame_config, &ref_frame_comp_pred,
2163 &use_svc_control, slx, is_key_frame,
2164 (app_input.layering_mode == 10), app_input.speed,
2165 &reference_updated, test_roi_map);
2167 if (use_svc_control) {
2171 &ref_frame_comp_pred);
2173 if (app_input.multilayer_metadata_file != NULL) {
2174 add_multilayer_metadata(&raw, multilayer_metadata, frame_cnt, slx);
2177 if (test_speed_per_layer) {
2178 int speed_per_layer = 10;
2200 if (ts_number_layers == 2) {
2202 }
else if (ts_number_layers == 3) {
2203 if (frame_cnt % 2 != 0)
2205 else if ((frame_cnt > 1) && ((frame_cnt - 2) % 4 == 0))
2219 const int err_resil_mode =
2226 if (frame_avail && slx == 0) ++rc.layer_input_frames[layer];
2228 if (test_dynamic_scaling_single_layer) {
2231 int frame_2x2 = 200;
2232 int frame_4x4 = 400;
2233 int frame_2x2up = 600;
2234 int frame_orig = 800;
2235 if (frame_cnt >= frame_2x2 && frame_cnt < frame_4x4) {
2239 }
else if (frame_cnt >= frame_4x4 && frame_cnt < frame_2x2up) {
2243 }
else if (frame_cnt >= frame_2x2up && frame_cnt < frame_orig) {
2247 }
else if (frame_cnt >= frame_orig) {
2252 if (frame_cnt == frame_2x2 || frame_cnt == frame_4x4 ||
2253 frame_cnt == frame_2x2up || frame_cnt == frame_orig) {
2259 for (i = 0; i < REF_FRAMES; i++) ref_frame_config.
refresh[i] = 1;
2260 if (use_svc_control) {
2264 &ref_frame_comp_pred);
2270 if (test_changing_bitrate && frame_cnt % 2 == 0) {
2271 if (frame_cnt < 500)
2283 die_codec(&codec,
"Failed to SET_BITRATE_ONE_PASS_CBR");
2287 aom::AV1FrameParamsRTC frame_params;
2289 frame_params.spatial_layer_id = 0;
2290 frame_params.temporal_layer_id = 0;
2291 frame_params.frame_type =
2292 is_key_frame ? aom::kKeyFrame : aom::kInterFrame;
2293 rc_api->ComputeQP(frame_params);
2294 const int current_qp = rc_api->GetQP();
2296 qindex_to_quantizer(current_qp))) {
2297 die_codec(&codec,
"Failed to SET_QUANTIZER_ONE_PASS");
2301 if (test_active_maps) set_active_map(&cfg, &codec, frame_cnt);
2303 if (test_roi_map) set_roi_map(&cfg, &codec, kDeltaQ);
2306 aom_usec_timer_start(&timer);
2308 die_codec(&codec,
"Failed to encode frame");
2309 aom_usec_timer_mark(&timer);
2310 cx_time += aom_usec_timer_elapsed(&timer);
2311 cx_time_layer[layer] += aom_usec_timer_elapsed(&timer);
2312 frame_cnt_layer[layer] += 1;
2315 int content_flag = 0;
2318 die_codec(&codec,
"Failed to GET_HIGH_MOTION_CONTENT_SCREEN_RTC");
2323 int ss_layers_write = (app_input.layering_mode == 11)
2327 switch (pkt->
kind) {
2333 int j = sl * ts_number_layers + tl;
2334 if (app_input.output_obu) {
2338 aom_video_writer_write_frame(
2340 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
2344 rc.layer_encoding_bitrate[j] += 8.0 * pkt->
data.
frame.
sz;
2349 if (app_input.output_obu) {
2351 total_layer_obu_file);
2353 aom_video_writer_write_frame(
2355 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
2363 rc.layer_avg_frame_size[j] += 8.0 * pkt->
data.
frame.
sz;
2364 rc.layer_avg_rate_mismatch[j] +=
2365 fabs(8.0 * pkt->
data.
frame.
sz - rc.layer_pfb[j]) /
2377 if (frame_cnt > rc.window_size && slx == ss_number_layers - 1) {
2378 sum_bitrate += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
2379 rc.window_size = (rc.window_size <= 0) ? 1 : rc.window_size;
2380 if (frame_cnt % rc.window_size == 0) {
2381 rc.window_count += 1;
2382 rc.avg_st_encoding_bitrate += sum_bitrate / rc.window_size;
2383 rc.variance_st_encoding_bitrate +=
2384 (sum_bitrate / rc.window_size) *
2385 (sum_bitrate / rc.window_size);
2390 if (frame_cnt > rc.window_size + rc.window_size / 2 &&
2391 slx == ss_number_layers - 1) {
2392 sum_bitrate2 += 0.001 * 8.0 * pkt->
data.
frame.
sz * framerate;
2393 if (frame_cnt > 2 * rc.window_size &&
2394 frame_cnt % rc.window_size == 0) {
2395 rc.window_count += 1;
2396 rc.avg_st_encoding_bitrate += sum_bitrate2 / rc.window_size;
2397 rc.variance_st_encoding_bitrate +=
2398 (sum_bitrate2 / rc.window_size) *
2399 (sum_bitrate2 / rc.window_size);
2404#if CONFIG_AV1_DECODER
2405 if (app_input.decode) {
2408 reinterpret_cast<const uint8_t *
>(pkt->
data.
frame.
buf),
2410 die_codec(&decoder,
"Failed to decode frame");
2416 if (app_input.show_psnr) {
2417 psnr_stream.psnr_sse_total[0] += pkt->
data.
psnr.sse[0];
2418 psnr_stream.psnr_samples_total[0] += pkt->
data.
psnr.samples[0];
2419 for (
int plane = 0; plane < 4; plane++) {
2420 psnr_stream.psnr_totals[0][plane] += pkt->
data.
psnr.psnr[plane];
2422 psnr_stream.psnr_count[0]++;
2428#if CONFIG_AV1_DECODER
2429 if (got_data && app_input.decode) {
2431 if (reference_updated) {
2432 if (test_decode(&codec, &decoder, frame_cnt)) {
2433#if CONFIG_INTERNAL_STATS
2434 fprintf(stats_file,
"First mismatch occurred in frame %d\n",
2438 fatal(
"Mismatch seen");
2445 pts += frame_duration;
2448 for (i = 0; i < MAX_NUM_SPATIAL_LAYERS; ++i) {
2449 if (app_input.input_ctx[i].filename == NULL) {
2452 close_input_file(&(app_input.input_ctx[i]));
2454 printout_rate_control_summary(&rc, frame_cnt, ss_number_layers,
2458 for (
int slx = 0; slx < ss_number_layers; slx++)
2459 for (
int tlx = 0; tlx < ts_number_layers; tlx++) {
2460 int lx = slx * ts_number_layers + tlx;
2461 printf(
"Per layer encoding time/FPS stats for encoder: %d %d %d %f %f \n",
2462 slx, tlx, frame_cnt_layer[lx],
2463 (
float)cx_time_layer[lx] / (
double)(frame_cnt_layer[lx] * 1000),
2464 1000000 * (
double)frame_cnt_layer[lx] / (
double)cx_time_layer[lx]);
2468 printf(
"Frame cnt and encoding time/FPS stats for encoding: %d %f %f\n",
2469 frame_cnt, 1000 * (
float)cx_time / (
double)(frame_cnt * 1000000),
2470 1000000 * (
double)frame_cnt / (
double)cx_time);
2472 if (app_input.show_psnr) {
2473 show_psnr(&psnr_stream, 255.0);
2478#if CONFIG_AV1_DECODER
2479 if (app_input.decode) {
2481 die_codec(&decoder,
"Failed to destroy decoder");
2485#if CONFIG_INTERNAL_STATS
2486 fprintf(stats_file,
"No mismatch detected in recon buffers\n");
2491 for (i = 0; i < ss_number_layers * ts_number_layers; ++i)
2492 aom_video_writer_close(outfile[i]);
2493 aom_video_writer_close(total_layer_file);
2495 if (has_non_y4m_input) {
2498 return EXIT_SUCCESS;
Describes the decoder algorithm interface to applications.
Describes the encoder algorithm interface to applications.
Describes the aom image descriptor and associated operations.
@ AOM_MIF_KEY_FRAME
Definition aom_image.h:176
@ AOM_MIF_ANY_FRAME_LAYER_SPECIFIC
Definition aom_image.h:183
@ AOM_CSP_UNKNOWN
Definition aom_image.h:143
enum aom_chroma_sample_position aom_chroma_sample_position_t
List of chroma sample positions.
#define AOM_IMG_FMT_HIGHBITDEPTH
Definition aom_image.h:38
aom_image_t * aom_img_alloc(aom_image_t *img, aom_img_fmt_t fmt, unsigned int d_w, unsigned int d_h, unsigned int align)
Open a descriptor, allocating storage for the underlying image.
@ AOM_IMG_FMT_I420
Definition aom_image.h:45
enum aom_img_fmt aom_img_fmt_t
List of supported image formats.
int aom_img_add_metadata(aom_image_t *img, uint32_t type, const uint8_t *data, size_t sz, aom_metadata_insert_flags_t insert_flag)
Add metadata to image.
void aom_img_free(aom_image_t *img)
Close an image descriptor.
Provides definitions for using AOM or AV1 encoder algorithm within the aom Codec Interface.
#define AOM_MAX_LAYERS
Definition aomcx.h:1777
#define AOM_MAX_TS_LAYERS
Definition aomcx.h:1779
aom_codec_iface_t * aom_codec_av1_cx(void)
The interface to the AV1 encoder.
struct aom_roi_map aom_roi_map_t
aom region of interest map
@ AOM_FULL_SUPERFRAME_DROP
Definition aomcx.h:1851
@ AV1E_SET_BITRATE_ONE_PASS_CBR
Codec control to set the target bitrate in kilobits per second, unsigned int parameter....
Definition aomcx.h:1544
@ AV1E_SET_ENABLE_SMOOTH_INTRA
Codec control function to turn on / off smooth intra modes usage, int parameter.
Definition aomcx.h:1081
@ AV1E_SET_ENABLE_TPL_MODEL
Codec control function to enable RDO modulated by frame temporal dependency, unsigned int parameter.
Definition aomcx.h:418
@ AV1E_SET_AQ_MODE
Codec control function to set adaptive quantization mode, unsigned int parameter.
Definition aomcx.h:478
@ AV1E_SET_SVC_LAYER_ID
Codec control function to set the layer id, aom_svc_layer_id_t* parameter.
Definition aomcx.h:1293
@ AV1E_SET_SVC_REF_FRAME_CONFIG
Codec control function to set the reference frame config, aom_svc_ref_frame_config_t* parameter.
Definition aomcx.h:1303
@ AV1E_SET_TUNE_CONTENT
Codec control function to set content type, aom_tune_content parameter.
Definition aomcx.h:507
@ AOME_SET_ROI_MAP
Codec control function to pass an ROI map to encoder, aom_roi_map_t* parameter.
Definition aomcx.h:185
@ AV1E_SET_CDF_UPDATE_MODE
Codec control function to set CDF update mode, unsigned int parameter.
Definition aomcx.h:516
@ AV1E_SET_ENABLE_ANGLE_DELTA
Codec control function to turn on/off intra angle delta, int parameter.
Definition aomcx.h:1128
@ AV1E_SET_MV_COST_UPD_FREQ
Control to set frequency of the cost updates for motion vectors, unsigned int parameter.
Definition aomcx.h:1271
@ AV1E_SET_INTRA_DEFAULT_TX_ONLY
Control to use default tx type only for intra modes, int parameter.
Definition aomcx.h:1220
@ AV1E_SET_SVC_REF_FRAME_COMP_PRED
Codec control function to set reference frame compound prediction. aom_svc_ref_frame_comp_pred_t* par...
Definition aomcx.h:1408
@ AV1E_SET_ENABLE_INTRABC
Codec control function to turn on/off intra block copy mode, int parameter.
Definition aomcx.h:1124
@ AV1E_SET_ENABLE_WARPED_MOTION
Codec control function to turn on / off warped motion usage at sequence level, int parameter.
Definition aomcx.h:1049
@ AV1E_SET_RTC_EXTERNAL_RC
Codec control function to set flag for rate control used by external encoders.
Definition aomcx.h:1443
@ AV1E_SET_COEFF_COST_UPD_FREQ
Control to set frequency of the cost updates for coefficients, unsigned int parameter.
Definition aomcx.h:1251
@ AV1E_SET_ENABLE_CDEF
Codec control function to encode with CDEF, unsigned int parameter.
Definition aomcx.h:681
@ AOME_SET_ACTIVEMAP
Codec control function to pass an Active map to encoder, aom_active_map_t* parameter.
Definition aomcx.h:190
@ AV1E_SET_DV_COST_UPD_FREQ
Control to set frequency of the cost updates for intrabc motion vectors, unsigned int parameter.
Definition aomcx.h:1374
@ AV1E_SET_SVC_FRAME_DROP_MODE
Codec control to set the frame drop mode for SVC, unsigned int parameter. The valid values are consta...
Definition aomcx.h:1557
@ AV1E_SET_SVC_PARAMS
Codec control function to set SVC parameters, aom_svc_params_t* parameter.
Definition aomcx.h:1298
@ AV1E_SET_ENABLE_FILTER_INTRA
Codec control function to turn on / off filter intra usage at sequence level, int parameter.
Definition aomcx.h:1070
@ AV1E_SET_ENABLE_PALETTE
Codec control function to turn on/off palette mode, int parameter.
Definition aomcx.h:1120
@ AV1E_SET_ENABLE_CFL_INTRA
Codec control function to turn on / off CFL uv intra mode usage, int parameter.
Definition aomcx.h:1099
@ AOME_SET_MAX_INTRA_BITRATE_PCT
Codec control function to set max data rate for intra frames, unsigned int parameter.
Definition aomcx.h:312
@ AV1E_SET_ERROR_RESILIENT_MODE
Codec control function to enable error_resilient_mode, int parameter.
Definition aomcx.h:452
@ AV1E_SET_ENABLE_OBMC
Codec control function to predict with OBMC mode, unsigned int parameter.
Definition aomcx.h:708
@ AV1E_SET_AUTO_TILES
Codec control to set auto tiling, unsigned int parameter. Value of 1 means encoder will set number of...
Definition aomcx.h:1565
@ AV1E_SET_LOOPFILTER_CONTROL
Codec control to control loop filter.
Definition aomcx.h:1423
@ AOME_SET_SCALEMODE
Codec control function to set encoder scaling mode for the next frame to be coded,...
Definition aomcx.h:197
@ AV1E_SET_ENABLE_ORDER_HINT
Codec control function to turn on / off frame order hint (int parameter). Affects: joint compound mod...
Definition aomcx.h:876
@ AV1E_SET_DELTAQ_MODE
Codec control function to set the delta q mode, unsigned int parameter.
Definition aomcx.h:1148
@ AV1E_SET_POSTENCODE_DROP_RTC
Codec control to enable post encode frame drop for RTC encoding, int parameter.
Definition aomcx.h:1581
@ AV1E_SET_ENABLE_GLOBAL_MOTION
Codec control function to turn on / off global motion usage for a sequence, int parameter.
Definition aomcx.h:1039
@ AOME_SET_CPUUSED
Codec control function to set encoder internal speed settings, int parameter.
Definition aomcx.h:220
@ AV1E_GET_HIGH_MOTION_CONTENT_SCREEN_RTC
Codec control to get the high motion content flag, used for screen content realtime (RTC) encoding,...
Definition aomcx.h:1572
@ AV1E_SET_GF_CBR_BOOST_PCT
Boost percentage for Golden Frame in CBR mode, unsigned int parameter.
Definition aomcx.h:349
@ AV1E_SET_QUANTIZER_ONE_PASS
Codec control to set quantizer for the next frame, int parameter.
Definition aomcx.h:1506
@ AV1E_SET_MODE_COST_UPD_FREQ
Control to set frequency of the cost updates for mode, unsigned int parameter.
Definition aomcx.h:1261
@ AV1E_SET_MAX_CONSEC_FRAME_DROP_MS_CBR
Codec control to set the maximum number of consecutive frame drops, in units of time (milliseconds),...
Definition aomcx.h:1587
@ AV1_GET_NEW_FRAME_IMAGE
Codec control function to get a pointer to the new frame.
Definition aom.h:70
const char * aom_codec_iface_name(aom_codec_iface_t *iface)
Return the name for a given interface.
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
aom_codec_err_t aom_codec_control(aom_codec_ctx_t *ctx, int ctrl_id,...)
Algorithm Control.
long aom_codec_flags_t
Initialization-time Feature Enabling.
Definition aom_codec.h:232
const struct aom_codec_iface aom_codec_iface_t
Codec interface structure.
Definition aom_codec.h:271
aom_codec_err_t aom_codec_destroy(aom_codec_ctx_t *ctx)
Destroy a codec instance.
const char * aom_codec_err_to_string(aom_codec_err_t err)
Convert error number to printable string.
aom_codec_err_t
Algorithm return codes.
Definition aom_codec.h:155
#define AOM_CODEC_CONTROL_TYPECHECKED(ctx, id, data)
aom_codec_control wrapper macro (adds type-checking, less flexible)
Definition aom_codec.h:542
const void * aom_codec_iter_t
Iterator.
Definition aom_codec.h:305
#define AOM_FRAME_IS_KEY
Definition aom_codec.h:288
@ AOM_BITS_8
Definition aom_codec.h:336
@ AOM_BITS_10
Definition aom_codec.h:337
@ AOM_CODEC_INVALID_PARAM
An application-supplied parameter is not valid.
Definition aom_codec.h:200
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition aom_codec.h:163
@ AOM_CODEC_OK
Operation completed without error.
Definition aom_codec.h:157
aom_codec_err_t aom_codec_decode(aom_codec_ctx_t *ctx, const uint8_t *data, size_t data_sz, void *user_priv)
Decode data.
#define aom_codec_dec_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_dec_init_ver()
Definition aom_decoder.h:129
#define AOM_USAGE_GOOD_QUALITY
usage parameter analogous to AV1 GOOD QUALITY mode.
Definition aom_encoder.h:1014
const aom_codec_cx_pkt_t * aom_codec_get_cx_data(aom_codec_ctx_t *ctx, aom_codec_iter_t *iter)
Encoded data iterator.
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img, aom_codec_pts_t pts, unsigned long duration, aom_enc_frame_flags_t flags)
Encode a frame.
#define aom_codec_enc_init(ctx, iface, cfg, flags)
Convenience macro for aom_codec_enc_init_ver()
Definition aom_encoder.h:943
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg, unsigned int usage)
Get the default configuration for a usage.
#define AOM_USAGE_REALTIME
usage parameter analogous to AV1 REALTIME mode.
Definition aom_encoder.h:1016
#define AOM_CODEC_USE_HIGHBITDEPTH
Definition aom_encoder.h:80
#define AOM_CODEC_USE_PSNR
Initialization-time Feature Enabling.
Definition aom_encoder.h:79
@ AOM_CBR
Definition aom_encoder.h:187
@ AOM_KF_AUTO
Definition aom_encoder.h:202
@ AOM_CODEC_PSNR_PKT
Definition aom_encoder.h:113
@ AOM_CODEC_CX_FRAME_PKT
Definition aom_encoder.h:110
aom active region map
Definition aomcx.h:1675
unsigned int rows
Definition aomcx.h:1678
unsigned int cols
Definition aomcx.h:1679
unsigned char * active_map
specify an on (1) or off (0) each 16x16 region within a frame
Definition aomcx.h:1677
Codec context structure.
Definition aom_codec.h:315
Encoder output packet.
Definition aom_encoder.h:122
size_t sz
Definition aom_encoder.h:127
enum aom_codec_cx_pkt_kind kind
Definition aom_encoder.h:123
double psnr[4]
Definition aom_encoder.h:145
union aom_codec_cx_pkt::@1 data
struct aom_codec_cx_pkt::@1::@2 frame
aom_codec_frame_flags_t flags
Definition aom_encoder.h:132
void * buf
Definition aom_encoder.h:126
Encoder configuration structure.
Definition aom_encoder.h:387
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition aom_encoder.h:475
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition aom_encoder.h:540
struct aom_rational g_timebase
Stream timebase units.
Definition aom_encoder.h:489
unsigned int g_usage
Algorithm specific "usage" value.
Definition aom_encoder.h:399
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition aom_encoder.h:705
unsigned int g_h
Height of the frame.
Definition aom_encoder.h:435
enum aom_kf_mode kf_mode
Keyframe placement mode.
Definition aom_encoder.h:768
enum aom_rc_mode rc_end_usage
Rate control algorithm to use.
Definition aom_encoder.h:623
unsigned int g_threads
Maximum number of threads to use.
Definition aom_encoder.h:407
unsigned int kf_min_dist
Keyframe minimum interval.
Definition aom_encoder.h:777
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition aom_encoder.h:518
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition aom_encoder.h:714
unsigned int g_profile
Bitstream profile to use.
Definition aom_encoder.h:417
aom_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition aom_encoder.h:467
unsigned int g_w
Width of the frame.
Definition aom_encoder.h:426
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition aom_encoder.h:681
unsigned int kf_max_dist
Keyframe maximum interval.
Definition aom_encoder.h:786
aom_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition aom_encoder.h:497
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition aom_encoder.h:668
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition aom_encoder.h:723
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition aom_encoder.h:658
unsigned int rc_target_bitrate
Target data rate.
Definition aom_encoder.h:644
unsigned int rc_resize_mode
Mode for spatial resampling, if supported by the codec.
Definition aom_encoder.h:549
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition aom_encoder.h:690
Image Descriptor.
Definition aom_image.h:198
aom_img_fmt_t fmt
Definition aom_image.h:199
unsigned int d_w
Definition aom_image.h:213
unsigned int d_h
Definition aom_image.h:214
int num
Definition aom_encoder.h:165
int den
Definition aom_encoder.h:166
aom region of interest map
Definition aomcx.h:1653
unsigned int cols
Definition aomcx.h:1659
int delta_lf[8]
Definition aomcx.h:1661
int ref_frame[8]
Definition aomcx.h:1663
unsigned int rows
Definition aomcx.h:1658
unsigned char * roi_map
Definition aomcx.h:1657
int delta_q[8]
Definition aomcx.h:1660
uint8_t enabled
Definition aomcx.h:1655
int skip[8]
Definition aomcx.h:1662
aom image scaling mode
Definition aomcx.h:1687
Struct for spatial and temporal layer ID.
Definition aomcx.h:1782
int temporal_layer_id
Definition aomcx.h:1784
int spatial_layer_id
Definition aomcx.h:1783
Parameter type for SVC.
Definition aomcx.h:1793
int max_quantizers[32]
Definition aomcx.h:1808
int number_spatial_layers
Definition aomcx.h:1800
int layer_target_bitrate[32]
Definition aomcx.h:1813
int framerate_factor[8]
Definition aomcx.h:1815
int min_quantizers[32]
Definition aomcx.h:1809
int scaling_factor_den[4]
Definition aomcx.h:1811
int number_temporal_layers
Definition aomcx.h:1807
int scaling_factor_num[4]
Definition aomcx.h:1810
Parameters for setting ref frame compound prediction.
Definition aomcx.h:1842
int use_comp_pred[3]
Definition aomcx.h:1845
Parameters for setting ref frame config.
Definition aomcx.h:1819
int reference[7]
Definition aomcx.h:1835
int refresh[8]
Definition aomcx.h:1838
int ref_idx[7]
Definition aomcx.h:1837